package enhance

import "fmt"

type BaseName interface {
	GetName() string
	SetName(name string)
}

type BaseInfo interface {
	GetInstance() int
	SetInstance(instance int)
}

type BaseNameImpl struct {
	name string
}

func (baseName *BaseNameImpl) GetName() string {
	return baseName.name
}

func (baseName *BaseNameImpl) SetName(name string) {
	baseName.name = name
}

type BaseInfoImpl struct {
	instance int
}

func (baseInfo *BaseInfoImpl) GetInstance() int {
	return baseInfo.instance
}

func (baseInfo *BaseInfoImpl) SetInstance(instance int) {
	fmt.Println(instance)
	baseInfo.instance = instance
}

type EnhanceBase struct {
	// 通过匿名字段获取和继承类似的复用能力
	BaseNameImpl
	BaseInfoImpl
	name string
}

func (enhanceBase *EnhanceBase) GetName() string {
	return enhanceBase.name
}

func (enhanceBase *EnhanceBase) SetName(name string) {
	enhanceBase.name = name
}

// MyInterface 接口
type MyInterface interface {
	DoSomething() string
}

// 结构体 A
type A struct{}

func (a A) DoSomething() string {
	fmt.Println("A.DoSomething()")
	return "A"
}

// 结构体 B
type B struct{}

func (b B) DoSomething() string {
	fmt.Println("B.DoSomething()")
	return "B"
}

// 结构体 C 匿名嵌入了 A 和 B
type C struct {
	A
	B
}

func (c C) DoSomething() string {
	fmt.Println("C.DoSomething()")
	return "C"
}
